// ignore_for_file: prefer_const_literals_to_create_immutables, prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:time_manager/components/animation_widget.dart';
import 'package:time_manager/components/left_item.dart';
import 'package:time_manager/global/controller/record_item_controller.dart';

import 'package:time_manager/utils/RecordModel.dart';

import 'package:time_manager/view/inThePast/past_controller.dart';

class PastView extends StatelessWidget {
  PastView({Key? key}) : super(key: key);

  final controller = Get.find<RecordItemController>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('所有日程')),
      body: Container(
        // padding: EdgeInsets.only(bottom: 20),
        color: Color(0xffeeeeee),
        child: RefreshIndicator(
          onRefresh: controller.onRefresh,
          child: Obx(() {
            return controller.list.isEmpty
                ? ListView(
                    children: [
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          SizedBox(
                            height: 100,
                          ),
                          Image.asset(
                            'assets/images/order_empty.png',
                            width: Get.width - 150,
                          ),
                          Text('您还没有新建过日程'),
                          Text('可以快速到首页去创建')
                        ],
                      ),
                    ],
                  )
                : ListView.builder(
                    padding: EdgeInsets.only(bottom: 20),
                    itemCount: controller.list.length,
                    itemBuilder: (_, index) {
                      RecoreModel temp = controller.list[index];
                      return AnimationWidget(child: ItemContainer(item: temp));
                    });
          }),
        ),
      ),
    );
  }
}

class ItemContainer extends StatelessWidget {
  final controller = Get.find<RecordItemController>();
  final RecoreModel item;
  ItemContainer({Key? key, required this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        margin: const EdgeInsets.only(top: 10, left: 10, right: 10),
        padding: EdgeInsets.all(10),
        decoration: BoxDecoration(
            color: Colors.white,
            boxShadow: [
              BoxShadow(
                color: Colors.white,
                blurRadius: 10,
              )
            ],
            borderRadius: BorderRadius.circular(5.0)),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            LeftItem(item: item),
            Column(
              children: [
                Text(
                  item.status == '1' ? '未完成' : "已完成",
                  style: TextStyle(
                      color: item.status == '1' ? Colors.red : Colors.green),
                ),
                SizedBox(
                  height: 10,
                ),
                SizedBox(
                  height: 27,
                  child: ElevatedButton(
                    child: Text('删除'),
                    style: ElevatedButton.styleFrom(
                        minimumSize: Size(60, 27),
                        textStyle: TextStyle(fontSize: 13),
                        primary: Colors.red,
                        padding: EdgeInsets.all(0),
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(20))),
                    onPressed: () {
                      controller.deleteRecord(item);
                    },
                  ),
                )
              ],
            )
          ],
        ));
  }
}
